package com.donger.business.bi.config;

import com.bstek.ureport.UReportPropertyPlaceholderConfigurer;
import com.bstek.ureport.provider.report.ReportProvider;
import com.donger.business.bi.processor.UReportPropertyPlaceholderConfigurerPlus;
import com.donger.business.bi.provider.DfsReportProvider;
import com.donger.common.storage.OssProperties;
import com.donger.common.storage.service.OssTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

import java.util.Locale;

@ConditionalOnClass(OssTemplate.class)
@Configuration
public class UreportExtConfig {

    @Bean
    public ReportProvider dfsReportProvider(OssTemplate ossTemplate, OssProperties properties) {
        return new DfsReportProvider(ossTemplate, properties);
    }

    @Bean
    public UReportPropertyPlaceholderConfigurer uReportPropertyPlaceholderConfigurerPlus() {
        return new UReportPropertyPlaceholderConfigurerPlus();
    }

    @Bean
    @Primary
    public LocaleResolver localeResolver() {

        AcceptHeaderLocaleResolver lr = new AcceptHeaderLocaleResolver();

        // 设置默认区域,

        lr.setDefaultLocale(Locale.CHINA);

        return lr;

    }
}
